<template>
	<view class="u-page">
		<view>
			<image src="https://static.talkxj.com/config/ebae4c93de1b286a8d50aa62612caa59.jpeg" style="width: 100%;">
		</view>
		
		
		
		<br>
		<view style="font-size: 50rpx;font-style: oblique; padding-left: 50rpx;">基本信息：</view>
		<br>
		<view class="u-demo-block" style="padding-left: 50rpx;">
			<view class="u-demo-block__content">
				<view class="u-page__upload-item">
					<u-upload
						:fileList="fileList6"
						@afterRead="afterRead"
						@delete="deletePic"
						name="6"
						multiple
						:maxCount="1"
						width="100"
						height="100"

					>
					
					</u-upload>
				</view>
			</view>
		</view>
		
		
		<view style="padding-left: 50rpx;padding-top: 20rpx; font-size: 25rpx;">昵称</view>
		  <u--input 
			placeholder="请输入你的昵称"
			border="bottom"
			clearable
		  ></u--input>

				
			<view style="padding-left: 50rpx;padding-top: 20rpx; font-size: 25rpx;">密码</view>	
		  <u--input
		    placeholder="请输入你的密码"
		    border="bottom"
		    clearable
		  ></u--input>

		<button style="width: 20%; background-color: #2979FF; left: -35%; top: 20rpx">修改</button>
	</view>
	
	
</template>

<script>
	export default {
		data() {
			return {

				fileList6: []
			}
		},
		onLoad() {
		},
		methods: {
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://localhost:8088/users/avatar', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							console.log(res);
							setTimeout(() => {
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		},
	}
</script>

<style lang="scss">
	.u-page {
		&__upload-item{
			margin-top:5px;
		}
	}
	.input1{
		width: 500rpx;
		
	}
</style>